package com.onpositive.simple.persistance;

public class SearchIndexFactory {
	
	static int STRING_INDEX_NODE_HALFSIZE = 1 ;
	static int INTEGER_INDEX_NODE_HALFSIZE = 1 ;
	static String RAM_TYPE = "RAM_TYPE" ;
	static String FS_TYPE = "FS_TYPE" ;
	static int stringIndexCount = 0 ;
	static int intIndexCount = 0 ;
	
	public static SearchIndex<?> constructSearchIndex( Class<?> clazz , AbstractObjectStore<?> _store ){
		
		if( _store.getStorageType() == RAM_TYPE )
		{
		
			if ( clazz == String.class ) {
				StringIndex stringIndex = new StringIndex( _store.stringStorage, STRING_INDEX_NODE_HALFSIZE,
					new RAMNodeStorage( TreeSearchIndex.getNodeSize(STRING_INDEX_NODE_HALFSIZE) ) );
				return stringIndex ;
			}
		
			if( ( clazz == Boolean.class )||( clazz == boolean.class ))
			return new BooleanIndex() ;
		
			return new IntegerIndex( INTEGER_INDEX_NODE_HALFSIZE, new RAMNodeStorage( TreeSearchIndex.getNodeSize(INTEGER_INDEX_NODE_HALFSIZE) ) ) ;
		}
		if( _store.getStorageType() == FS_TYPE )
		{		
			if ( clazz == String.class ) {
				StringIndex stringIndex = new StringIndex( _store.stringStorage, STRING_INDEX_NODE_HALFSIZE,
					new FSNodeStorage( TreeSearchIndex.getNodeSize(STRING_INDEX_NODE_HALFSIZE) , _store.getPath(),
							"_str"+(stringIndexCount++) ) );
				return stringIndex ;
			}
		
			if( ( clazz == Boolean.class )||( clazz == boolean.class ))
			return new BooleanIndex() ;
		
			return new IntegerIndex( INTEGER_INDEX_NODE_HALFSIZE, new FSNodeStorage( TreeSearchIndex.getNodeSize(INTEGER_INDEX_NODE_HALFSIZE),_store.getPath(),
					"_int"+(intIndexCount++)) ) ;
		}
		return null;		
	}
}

